<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="jrProductName">
        <el-input
          v-model="queryParams.jrProductName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资方信息ID" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          placeholder="请输入资方信息ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资金提供方" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入资金提供方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分期期限(-1表示无限期)" prop="instalmentPeriod">
        <el-input
          v-model="queryParams.instalmentPeriod"
          placeholder="请输入分期期限(-1表示无限期)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="授信额度(单位：%，比如80%，存的是80)" prop="creditLine">
        <el-input
          v-model="queryParams.creditLine"
          placeholder="请输入授信额度(单位：%，比如80%，存的是80)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCardNumber">
        <el-input
          v-model="queryParams.bankCardNumber"
          placeholder="请输入银行卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户银行ID" prop="bankId">
        <el-input
          v-model="queryParams.bankId"
          placeholder="请输入开户银行ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行名称" prop="bankName">
        <el-input
          v-model="queryParams.bankName"
          placeholder="请输入银行名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户行(支行)" prop="openingBank">
        <el-input
          v-model="queryParams.openingBank"
          placeholder="请输入开户行(支行)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户名称" prop="accountName">
        <el-input
          v-model="queryParams.accountName"
          placeholder="请输入账户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联行行号" prop="bankBranchCodeLh">
        <el-input
          v-model="queryParams.bankBranchCodeLh"
          placeholder="请输入联行行号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户行所在省ID" prop="bankAccountProvince">
        <el-input
          v-model="queryParams.bankAccountProvince"
          placeholder="请输入开户行所在省ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请条件" prop="applicationConditions">
        <el-input
          v-model="queryParams.applicationConditions"
          placeholder="请输入申请条件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="风控要求" prop="riskRequirement">
        <el-input
          v-model="queryParams.riskRequirement"
          placeholder="请输入风控要求"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="预留字段1" prop="reserve1">
        <el-input
          v-model="queryParams.reserve1"
          placeholder="请输入预留字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段2" prop="reserve2">
        <el-input
          v-model="queryParams.reserve2"
          placeholder="请输入预留字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段3" prop="reserve3">
        <el-input
          v-model="queryParams.reserve3"
          placeholder="请输入预留字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段4" prop="reserve4">
        <el-input
          v-model="queryParams.reserve4"
          placeholder="请输入预留字段4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段5" prop="reserve5">
        <el-input
          v-model="queryParams.reserve5"
          placeholder="请输入预留字段5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="删除标识
,0:未删除，1：删除" prop="delFlg">
        <el-input
          v-model="queryParams.delFlg"
          placeholder="请输入删除标识
,0:未删除，1：删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建用户ID" prop="createUserid">
        <el-input
          v-model="queryParams.createUserid"
          placeholder="请输入创建用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新用户ID" prop="updateUserid">
        <el-input
          v-model="queryParams.updateUserid"
          placeholder="请输入更新用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:product:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:product:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:product:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:product:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键 自增" align="center" prop="id" />
      <el-table-column label="产品名称" align="center" prop="jrProductName" />
      <el-table-column label="资方信息ID" align="center" prop="companyId" />
      <el-table-column label="资金提供方" align="center" prop="companyName" />
      <el-table-column label="分期期限(-1表示无限期)" align="center" prop="instalmentPeriod" />
      <el-table-column label="授信额度(单位：%，比如80%，存的是80)" align="center" prop="creditLine" />
      <el-table-column label="金融产品类型,1：租房分期，2：收房贷，3：应收租约保理" align="center" prop="jrProductType" />
      <el-table-column label="还款方式,1：按月还款，2：按季还款，3：按租约周期支付" align="center" prop="repaymentType" />
      <el-table-column label="支付PC链接(URL)" align="center" prop="urlPayPc" />
      <el-table-column label="支付移动链接(URL)" align="center" prop="urlPayMoble" >
      </el-table-column>
      <el-table-column label="补全信息PC(URL)" align="center" prop="urlAddDetailInfoPc" />
      <el-table-column label="补全信息移动(URL)" align="center" prop="urlAddDetailInfoMobile" />
      <el-table-column label="App下载(URL)" align="center" prop="urlAppDownload" />
      <el-table-column label="银行账户类型" align="center" prop="accountType" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber" />
      <el-table-column label="开户银行ID" align="center" prop="bankId" />
      <el-table-column label="银行名称" align="center" prop="bankName" />
      <el-table-column label="开户行(支行)" align="center" prop="openingBank" />
      <el-table-column label="账户名称" align="center" prop="accountName" />
      <el-table-column label="联行行号" align="center" prop="bankBranchCodeLh" />
      <el-table-column label="开户行所在省ID" align="center" prop="bankAccountProvince" />
      <el-table-column label="申请条件" align="center" prop="applicationConditions" />
      <el-table-column label="风控要求" align="center" prop="riskRequirement" />
<!--      <el-table-column label="预留字段1" align="center" prop="reserve1" />
      <el-table-column label="预留字段2" align="center" prop="reserve2" />
      <el-table-column label="预留字段3" align="center" prop="reserve3" />
      <el-table-column label="预留字段4" align="center" prop="reserve4" />
      <el-table-column label="预留字段5" align="center" prop="reserve5" />-->
      <el-table-column label="删除标识
,0:未删除，1：删除" align="center" prop="delFlg" />
      <el-table-column label="创建用户ID" align="center" prop="createUserid" />
      <el-table-column label="更新用户ID" align="center" prop="updateUserid" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:product:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:product:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品名称" prop="jrProductName">
          <el-input v-model="form.jrProductName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="资方信息ID" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入资方信息ID" />
        </el-form-item>
        <el-form-item label="资金提供方" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入资金提供方" />
        </el-form-item>
        <el-form-item label="分期期限(-1表示无限期)" prop="instalmentPeriod">
          <el-input v-model="form.instalmentPeriod" placeholder="请输入分期期限(-1表示无限期)" />
        </el-form-item>
        <el-form-item label="授信额度(单位：%，比如80%，存的是80)" prop="creditLine">
          <el-input v-model="form.creditLine" placeholder="请输入授信额度(单位：%，比如80%，存的是80)" />
        </el-form-item>
        <el-form-item label="支付PC链接(URL)" prop="urlPayPc">
          <el-input v-model="form.urlPayPc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="支付移动链接(URL)" prop="urlPayMoble">
          <el-input v-model="form.urlPayMoble" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="补全信息PC(URL)" prop="urlAddDetailInfoPc">
          <el-input v-model="form.urlAddDetailInfoPc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="补全信息移动(URL)" prop="urlAddDetailInfoMobile">
          <el-input v-model="form.urlAddDetailInfoMobile" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="App下载(URL)" prop="urlAppDownload">
          <el-input v-model="form.urlAppDownload" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="开户银行ID" prop="bankId">
          <el-input v-model="form.bankId" placeholder="请输入开户银行ID" />
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称" />
        </el-form-item>
        <el-form-item label="开户行(支行)" prop="openingBank">
          <el-input v-model="form.openingBank" placeholder="请输入开户行(支行)" />
        </el-form-item>
        <el-form-item label="账户名称" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户名称" />
        </el-form-item>
        <el-form-item label="联行行号" prop="bankBranchCodeLh">
          <el-input v-model="form.bankBranchCodeLh" placeholder="请输入联行行号" />
        </el-form-item>
        <el-form-item label="开户行所在省ID" prop="bankAccountProvince">
          <el-input v-model="form.bankAccountProvince" placeholder="请输入开户行所在省ID" />
        </el-form-item>
        <el-form-item label="申请条件" prop="applicationConditions">
          <el-input v-model="form.applicationConditions" placeholder="请输入申请条件" />
        </el-form-item>
        <el-form-item label="风控要求" prop="riskRequirement">
          <el-input v-model="form.riskRequirement" placeholder="请输入风控要求" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识
,0:未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识
,0:未删除，1：删除" />
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProduct, getProduct, delProduct, addProduct, updateProduct } from "@/api/system/product";

export default {
  name: "Product",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jrProductName: null,
        companyId: null,
        companyName: null,
        instalmentPeriod: null,
        creditLine: null,
        jrProductType: null,
        repaymentType: null,
        urlPayPc: null,
        urlPayMoble: null,
        urlAddDetailInfoPc: null,
        urlAddDetailInfoMobile: null,
        urlAppDownload: null,
        accountType: null,
        bankCardNumber: null,
        bankId: null,
        bankName: null,
        openingBank: null,
        accountName: null,
        bankBranchCodeLh: null,
        bankAccountProvince: null,
        applicationConditions: null,
        riskRequirement: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        jrProductName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" }
        ],
        companyName: [
          { required: true, message: "资金提供方不能为空", trigger: "blur" }
        ],
        jrProductType: [
          { required: true, message: "金融产品类型，1：租房分期，2：收房贷，3：应收租约保理不能为空", trigger: "change" }
        ],
        repaymentType: [
          { required: true, message: "还款方式,1：按月还款，2：按季还款，3：按租约周期支付不能为空", trigger: "change" }
        ],
        delFlg: [
          { required: true, message: "删除标识,0:未删除，1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then(response => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        jrProductName: null,
        companyId: null,
        companyName: null,
        instalmentPeriod: null,
        creditLine: null,
        jrProductType: null,
        repaymentType: null,
        urlPayPc: null,
        urlPayMoble: null,
        urlAddDetailInfoPc: null,
        urlAddDetailInfoMobile: null,
        urlAppDownload: null,
        accountType: null,
        bankCardNumber: null,
        bankId: null,
        bankName: null,
        openingBank: null,
        accountName: null,
        bankBranchCodeLh: null,
        bankAccountProvince: null,
        applicationConditions: null,
        riskRequirement: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProduct(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProduct(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProduct(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delProduct(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/product/export', {
        ...this.queryParams
      }, `product_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
